package com.goktech.olala.server.dao.goods;

import com.goktech.olala.core.req.ReqCategory;
import com.goktech.olala.core.resp.RespGoodsCategory;
import com.goktech.olala.server.dao.goods.sql.GoodsCategorySql;
import com.goktech.olala.server.pojo.goods.GoodsCategory;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;
/**
 * @author wusq
 * 商品类别 dao层
 */
public interface GoodsCategoryMapper {
    /**
     * 多条件新增类别
     * @param record
     * @return
     */
    int insertByExample(GoodsCategory record);

    /**
     * 更新类别
     * @param record
     * @return
     */
    int updateByPrimaryKey(GoodsCategory record);

    /**
     * 通过id查询类别
     * @param categoryId
     * @return
     */
    GoodsCategory selectByPrimaryKey(Long categoryId);

    /**
     * 查询类别列表
     * @return
     */
    List<GoodsCategory> findCategoryTree();

    /**
     * 多条件查询
     * @param reqCategory
     * @return
     */
    @SelectProvider(type = GoodsCategorySql.class,method = "selectCategoryByExample")
    List<RespGoodsCategory> selectByExample(ReqCategory reqCategory);

    /**
     * 查询父类别
     * @return
     */
    @Select("SELECT GROUP_CONCAT(CATEGORY.CATEGORY_ID) categoryIdArr,GROUP_CONCAT(CATEGORY.CATEGORY_NAME SEPARATOR '/') categoryName, " +
            "GROUP_CONCAT(DISTINCT CATEGORY.CATY_DESC) catyDesc FROM G_CATEGORY CATEGORY WHERE CATEGORY.PARENT_ID = -1 " +
            "GROUP BY CATEGORY.FILTER_ATTR")
    List<RespGoodsCategory> selectBeParentCategory();
}